package es.ibm.santillana.mdm.common.util;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * BundleSantillana is the Collaboration Server Santillana Class used to
 *  store texts and components that are locale sensitive. Used in JSPs and other 
 *  classes that cannot be handled with Collaboration Server native tools.
 *  There are two ways to use this class:
 * <ul>
 * <li>Use one of the available constructors and the getMessage. (Better Performance)
 * <li>Use one of the available static class to obtain directly the message.
 * </ul>
 *  
 * @author      Diego Manso
 * @author      Benito Perez
 * @Version 	1.0
 * @since		1.0
 *
 */
public class BundleSantillana {

	private Locale locale;
	private ResourceBundle rb;
	
	/**
	 * Default constructor that uses default the default locale.
	 */
	public BundleSantillana(){
		rb = ResourceBundle.getBundle(ConstSantillana.MESSAGE_BUNDLE_FILENAME);
	}
	
	/**
	 * Constructor for specific locales.
	 * @param localeCode
	 */
	public BundleSantillana(String localeCode){
		locale = new Locale(localeCode);
		rb = ResourceBundle.getBundle(ConstSantillana.MESSAGE_BUNDLE_FILENAME, locale);
	}
	
	/**
	 * Constructor for specific locales and custom filename.
	 * @param localeCode
	 * @param propertiesFileName
	 */
	public BundleSantillana(String localeCode, String propertiesFileName){
		locale = new Locale(localeCode);
		rb = ResourceBundle.getBundle(propertiesFileName, locale);
	}
	
	/**
	 * Returns the message according to the passed key.
	 * @param key
	 * @return desired message.
	 */
	public String getMessage(String key){
		return rb.getString(key);
	}
	
	/**
	 *  Returns the message according to the passed key and locale code, used
	 *  if you dont want to use the contructor.
	 * @param localeCode
	 * @param key
	 * @return desired message
	 */
	public static String getMessage(String localeCode, String key){
		return ResourceBundle.getBundle(ConstSantillana.MESSAGE_BUNDLE_FILENAME, new Locale(localeCode)).getString(key);
	}
	
	/**
	 *  Returns the message according to the passed key, properties file name and locale code, used
	 *  if you dont want to use the contructor.
	 * @param localeCode
	 * @param propertiesFileName
	 * @param key
	 * @return desired message
	 */
	public static String getMessage(String localeCode, String propertiesFileName, String key){
		return ResourceBundle.getBundle(propertiesFileName, new Locale(localeCode)).getString(key);
	}
	
}
